package app

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"testPaper/common"
	"testPaper/model"
	"testPaper/response"
)

// PracticeTopic 练习
func PracticeTopic(c *gin.Context) {
	DB := common.GetDB()
	id := c.PostForm("id")
	tag_id := c.PostForm("tag_id")
	types := c.PostForm("types")
	paperId := c.PostForm("paperId")
	if paperId == "" {
		response.Reponse(c, http.StatusOK, 422, gin.H{"paperId": paperId}, "试卷获取失败")
		return
	}
	if types == "" {
		response.Reponse(c, http.StatusOK, 422, gin.H{"types": types}, "题目类型错误")
		return
	}
	if tag_id == "" {
		response.Reponse(c, http.StatusOK, 422, gin.H{"types": types}, "标签未传入")
		return
	}
	var topic = make([]model.Topic, 0)
	sql := "SELECT * FROM `topics` WHERE type = '" + types + "' AND paper_id = '" + paperId + "' AND tag_id = '" + tag_id + "' AND id != '" + id + "' order by rand() LIMIT 1"

	DB.Debug().Raw(sql).Scan(&topic)
	response.Reponse(c, http.StatusOK, 200, gin.H{"data": topic}, "ok")
	return
}
